package woaini.wind.bot.job.utils;

import cn.hutool.core.collection.CollUtil;
import lombok.experimental.UtilityClass;
import woaini.wind.bot.api.holidays.dto.HolidaysResponseDayDTO;

import java.time.LocalDate;
import java.util.Map;

@UtilityClass
public class HolidaysTool {

  public HolidaysResponseDayDTO nextHolidayInfo(Map<String, HolidaysResponseDayDTO> holidayInfos){
    if (CollUtil.isEmpty(holidayInfos)){
      return null;
    }
    //获取明天
    LocalDate searchDate = LocalDate.now().plusDays(1);
    //获取今年结束日期
    LocalDate endDate = LocalDate.now().withDayOfYear(LocalDate.now().lengthOfYear());
    //查找下一个节假日 不是补班的
    while (searchDate.isBefore(endDate)){
      HolidaysResponseDayDTO holidaysResponseDayDTO = holidayInfos.get(searchDate.toString());
      if (holidaysResponseDayDTO != null && holidaysResponseDayDTO.getIsOffDay()){
        return holidaysResponseDayDTO;
      }
      searchDate = searchDate.plusDays(1);
    }
    return null;
  }
}
